<?php
/**
 * Created by PhpStorm.
 * User: fenfen
 * Date: 2017/1/3
 * Time: 17:51
 */

namespace bc\model;

use bc\ar\MActiveRecord;
class UserreportModel extends MActiveRecord
{
    public static function tableName()
    {
        return '{{%user_report}}';
    }

    public function getInfoFromBindno($product_id,$bind_no)
    {
        if(empty($product_id)||empty($bind_no)){
            return array();
        }
        $data=array();
        $where='bc_user_report.product_id='.$product_id.
            ' and bc_report_lookup.product_id='.$product_id.
            ' and bc_user_report.bind_no='."'".$bind_no."'".
            ' and bc_report_lookup.deleted='.'0'.
            ' and bc_user_report.deleted='.'0'.
            ' and bc_user_report.report_value >= bc_report_lookup.min_value and bc_user_report.report_value <= bc_report_lookup.max_value';

        $this->columns="bc_report_lookup.id as lid,bc_report_lookup.report_key,bc_report_lookup.lookup_value";
        $ar=$this->find ()->select( $this->columns )->leftJoin('bc_report_lookup', 'bc_user_report.report_key = bc_report_lookup.user_report_key')->where($where);
//        echo $ar->createCommand()->getRawSql();
        $infoList= $ar->asArray ()->all ();

        foreach($infoList as $k => $value){
            $data[$value['report_key']]=$value['lookup_value'];
           // $notin[]=$value['lid'];
        }

        $where='bc_user_report.product_id='.$product_id.
            ' and bc_user_report.bind_no='."'".$bind_no."'".
            ' and bc_user_report.deleted='.'0';
           // ' and bc_user_report.id not in ('. implode(',', $notin).')';

        $this->columns="report_key,report_value";
        $ar=$this->find ()->select( $this->columns )->where($where);
        $infoList= $ar->asArray ()->all ();
        foreach($infoList as $k => $value){
            $data[$value['report_key']]=$value['report_value'];
        }

        return $data;
    }
}